<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>天气案例</title>
    <script src="js/vue.js"></script>
</head>
<body>
<div id="root">
    <h2>今天天气好{{infor}}</h2>
    <button @click="changeWeather">切换</button>
</div>
<script>
    Vue.config.productionTip = false;
    const vm = new Vue({
        el: '#root',
        data: {
            isHot: true
        },
        computed: {
            infor() {
                return this.isHot ? '炎热' : '凉爽';
            }
        },
        methods: {
            changeWeather() {
                this.isHot = !this.isHot;
            }
        },
        watch: {
            isHot: {
                // 初始化handler立即执行一次
                immediate: true,
                // 当isHot被修改的时候调用
                handled(newVal, oldVal) {

                }
            }
        }
    });
    // 动态添加监测对象
    vm.$watch('isHot', {
        // 初始化handler立即执行一次
        immediate: true,
        // 当isHot被修改的时候调用
        handled(newVal, oldVal) {

        }
    });
</script>
</body>
</html>